package com.audaque.springboot.foshanupload.web.esdatademo.controller;

/**
 * @author zhongguobin
 * @date 2024-04-03 11:44
 * @description TODO
 */


import com.audaque.springboot.foshanupload.web.esdatademo.model.pojo.UserDto;
import com.audaque.springboot.foshanupload.web.esdatademo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/elasticsearch")
public class UserRepositoryController {
    @Autowired
    private UserRepository userRepository;

    /**
     * 插入
     *
     * @return
     */
    @PostMapping("/insert")
    public UserDto insert(UserDto userDto) {
        return userRepository.save(userDto);
    }

    /**
     * 根据用户名获取用户信息
     *
     * @return
     */
    @GetMapping("/query")
    public UserDto query(String username) {
        return userRepository.getUserDtoByUsername(username);
    }

    /**
     * 更新
     *
     * @return
     */
    @PostMapping("/update")
    public UserDto update(UserDto userDto) {
        return userRepository.save(userDto);
    }

    /**
     * 删除
     *
     * @return
     */
    @DeleteMapping("/delete")
    public void delete(UserDto userDto) {
        userRepository.delete(userDto);
    }
}